import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import databaseConfig from '../../config/database.config';
import { User } from './entities/user.entity';
import { UserController } from './user.controller';
import { UserService } from './user.service';

@Module({
  imports: [
    ConfigModule.forRoot({
      load: [databaseConfig], // 加载数据库配置
    }),
    // TypeOrmModule.forRootAsync({
    //   imports: [ConfigModule], // 只导入 ConfigModule
    //   useFactory: (configService: ConfigService) => ({
    //     type: 'mysql',
    //     host: configService.get<string>('database.host', 'localhost'), // 默认值为 'localhost'
    //     port: configService.get<number>('database.port', 3306), // 默认值为 3306
    //     username: configService.get<string>('database.username', 'root'), // 默认值为 'root'
    //     password: configService.get<string>('database.password', '123456'), // 默认值为 'password'
    //     database: configService.get<string>('database.name', 'test'), // 默认值为 'test'
    //     entities: [__dirname + '/../../**/*.entity[.ts,.js]'], // 确保路径正确
    //     synchronize: configService.get<boolean>('database.synchronize', true), // 默认值为 true
    //   }),
    //   inject: [ConfigService],
    // }),
    TypeOrmModule.forFeature([User]), // 注册 User 实体
  ],
  controllers: [UserController],
  providers: [UserService],
})
export class UserModule {}